<?php
use App\Models\Order;
use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

// Route::get('/user', function (Request $request) {
//     return $request->user();
// })->middleware('auth:api');

Route::get('/getdata/{symbol}', function ($symbol) {
     $data = get_option_data($symbol);
     echo json_encode($data);
     //var_dump($data);
});

Route::get('/getperioddata/{symbol}', function ($symbol) {
     $data = get_period_data($symbol);
     //echo $data;
     echo json_encode($data);
     //var_dump($data);
});

Route::get('/getklinedata/{symbol}/{time}', function ($symbol,$time) {
     $data = get_k_data($symbol,$time);
     //echo $data;
     echo json_encode($data);
     //var_dump($data);
});

Route::get('/getorderdata/{id}', function ($id) {
     $data = Order::where('id','=',$id)->first();
     //echo $data;
     echo json_encode($data);
     //var_dump($data);
});

Route::group(['namespace' => 'Admin\Wechat'], function () {
    Route::any('/wechat', 'WechatController@serve');
});

Route::group(['namespace' => 'Home'], function () {
    Route::any('/wxpaynotify','MemberController@wxPayNotify');
    Route::any('/zfnotify','MemberController@zfnotify');
});

Route::get('/test/{code}', function ($code) {
    $url="http://code.jrjimg.cn/code?1=1item=20&type=cn_i,s&key=".$code;
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     $output = curl_exec($ch);
     curl_close($ch);
     $output = mb_convert_encoding($output, 'utf-8', 'gbk');
     $res=ltrim($output,'var SCodeData={CodeData:');
     $arr=explode(",Summary",$res);
     $str=str_replace(':','":',$arr[0]);
     $str=str_replace('",','","',$str);
     echo $str=str_replace('{','{"',$str);
});